import request from '@/utils/request'

const DEFAULT_OAUTH = {
  client_id: 'gulimall-web',
  client_secret: 'secret',
  grant_type: 'password',
  username: '',
  password: ''
}

export function loginREQ(params) {
  DEFAULT_OAUTH.username = params.username
  DEFAULT_OAUTH.password = params.password
  return request({
    url: '/auto/oauth/token',
    method: 'post',
    params: DEFAULT_OAUTH,
    headers: { 'No-Token': true }
  })
}

export function logoutREQ() {
  return request({
    url: '/auto/token/logout',
    method: 'delete'
  })
}

export function personalREQ() {
  return request({
    url: '/sys/personal/personal_info',
    method: 'GET'
  })
}

const DEFAULT_REFRESH_TOKEN = {
  client_id: 'gulimall-web',
  client_secret: 'secret',
  grant_type: 'refresh_token',
  refresh_token: ''
}

export function refreshTokenREQ(refreshToken) {
  DEFAULT_REFRESH_TOKEN['refresh_token'] = refreshToken
  return request({
    url: '/auto/oauth/token',
    method: 'POST',
    params: DEFAULT_REFRESH_TOKEN,
    headers: { 'Grant-type': 'Refresh-token', 'No-Token': true }
  })
}
